package com.app.ytong.bean;


import com.alibaba.fastjson.annotation.JSONField;
import com.app.ytong.basis.Constants;

import java.util.ArrayList;

import my.FileUtils;

public class LoginServiceListBean extends BaseListBean {

    public static final String FILE_CACHE = Constants.DIR_FILECACHE
            + "login_servie.data";

    private ArrayList<LoginServiceListData> list = new ArrayList<LoginServiceListData>();

    @JSONField(name = "links")
    public ArrayList<LoginServiceListData> getList() {
        return list;
    }

    @JSONField(name = "links")
    public void setList(ArrayList<LoginServiceListData> list) {
        this.list = list;
    }


    public static LoginServiceListBean getFromCache() {
        LoginServiceListBean data = (LoginServiceListBean) FileUtils.readObject(FILE_CACHE);

        return data;
    }

    public void save() {
        FileUtils.cacheObject(FILE_CACHE, this);
        // FileSaveHandler.saveObject(FILE_CACHE, this);
    }

    private static void delete() {
        FileUtils.cacheObject(FILE_CACHE , null);
        // FileSaveHandler.removeObject(FILE_CACHE);
    }

    public LoginServiceListData getDateByService(String id){
        for(LoginServiceListData data:list){
            if(id.equals(data.getIp()))return data;
        }
        return null;
    }

    public  ArrayList<String> getListStringNameAndUrl(){
        ArrayList<String> listString = new ArrayList<>();
        for(LoginServiceListData data:list){
            listString.add(data.getName());
        }
        return  listString;
    }

//    public void formatData(){
//        for(LoginServiceListData data:list){
//            if(!data.getUrl().endsWith("/"))
//            data.setUrl(data.getUrl()+"/");
//        }
//    }

}
